import sympy as sp
import numpy as np

def set_chinese_font():
    """设置中文字体"""
    plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'DejaVu Sans']
    plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

set_chinese_font()

def equation_solving():
    x = sp.Symbol('x')
    y = sp.Symbol('y')
    
    equation = 2 * x + 5 - 13
    solution = sp.solve(equation, x)

    print(f"方程2x + 5 -13的解: x = {solution[0]}")

    # 一元二次方程
    equation2 = x**2 - 5*x +6
    solution2 = sp.solve(equation2, x)
    print(f"方程x² - 5x + 6 = 0的解: {solution2}")

    #方程组
    eq1 = 2 * x + 3 *y - 7
    eq2 = 4 * x - y -3
    solution3 = sp.solve((eq1, eq2), (x, y))
    print(f"方程组解:{solution3}" )


equation_solving()